package com.ruoyi.common.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * 读取项目相关配置
 *
 * @author ruoyi
 */
@Component
@ConfigurationProperties(prefix = "ruoyi")
public class RuoYiConfig
{
    //

    /**
     * 消息提示相关
     **/
    private final Message message = new Message();
    /**
     * 文件存储相关
     **/
    private final Minio minio = new Minio();
    /** 项目名称 */
    private String name;

    /** 版本 */
    private String version;

    /** 版权年份 */
    private String copyrightYear;

    /** 上传路径 */
    private static String profile;

    /** 获取地址开关 */
    private static boolean addressEnabled;

    /** 验证码类型 */
    private static String captchaType;

    private final WeChat wechat = new WeChat();

    public static class WeChat {
        private String appId = "wx367440e0e545bfc6";
        private String appScret = "7d8562093a02907df14801cc23a9fad1";

        /**
         * accesstoken 的redis key
         **/
        private String accesstokenKeyPrefix = "wechart:accesstoken";
        /**
         * 默认一小时
         **/
        private Integer accesstokenSecond = 3600;



        private String authorizeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=%s#wechat_redirect";
        /**
         * 小程序 验证码模式的accessToken
         **/
        private String accessTokenUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
        // private String accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
        private String userinfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
        /**
         * 客户端模式的accessToken
         **/
        private String clientAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?appid=%s&secret=%s&grant_type=client_credential";

        /**
         * 推送公众号消息模板url
         **/
        //private String templateMessageUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send";
        /**
         * 小程序
         * **/
        private String templateMessageUrl = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send";

        public Integer getAccesstokenSecond() {
            return accesstokenSecond;
        }

        public void setAccesstokenSecond(Integer accesstokenSecond) {
            this.accesstokenSecond = accesstokenSecond;
        }

        public String getAccesstokenKeyPrefix() {
            return accesstokenKeyPrefix;
        }

        public void setAccesstokenKeyPrefix(String accesstokenKeyPrefix) {
            this.accesstokenKeyPrefix = accesstokenKeyPrefix;
        }

        public String getTemplateMessageUrl() {
            return templateMessageUrl;
        }

        public void setTemplateMessageUrl(String templateMessageUrl) {
            this.templateMessageUrl = templateMessageUrl;
        }

        public String getClientAccessTokenUrl() {
            return clientAccessTokenUrl;
        }

        public void setClientAccessTokenUrl(String clientAccessTokenUrl) {
            this.clientAccessTokenUrl = clientAccessTokenUrl;
        }

        public String getAppId() {
            return appId;
        }

        public void setAppId(String appId) {
            this.appId = appId;
        }

        public String getAppScret() {
            return appScret;
        }

        public void setAppScret(String appScret) {
            this.appScret = appScret;
        }

        public String getAuthorizeUrl() {
            return authorizeUrl;
        }

        public void setAuthorizeUrl(String authorizeUrl) {
            this.authorizeUrl = authorizeUrl;
        }

        public String getAccessTokenUrl() {
            return accessTokenUrl;
        }

        public void setAccessTokenUrl(String accessTokenUrl) {
            this.accessTokenUrl = accessTokenUrl;
        }

        public String getUserinfoUrl() {
            return userinfoUrl;
        }

        public void setUserinfoUrl(String userinfoUrl) {
            this.userinfoUrl = userinfoUrl;
        }
    }

    public WeChat getWechat() {
        return wechat;
    }
    /**
     * 文件存储相关
     **/
    public static class Minio {

        private String[] includeFileExts;
        private String[] includeImgExts;
        private Long bufferSize = 4096L;
        //260316576
        private Long maxSize = 1048576000L;
        private String defaultEncoding = "UTF-8";
        /**
         * 允许的文件后缀名
         **/
        private String type = "jpg,png,jpeg,xls,xlsx,doc,docx,ppt,pptx,txt,pdf,zip,rar,mp3,mp4,apk";

        private String imgType = "jpg,png,jpeg";

        /**
         * 静态图片资源地址
         **/
        private String staticImageServer;

        private String bucketName;
        private String endpoint = "http://localhost:9011";
        private Integer port = 9011;
        private Boolean https = false;
        private String accessKey;
        private String secretKey;

        public String[] getIncludeFileExts() {
            if (this.includeFileExts == null) {
                if (!StringUtils.isEmpty(this.type)) {
                    this.includeFileExts = this.type.split(",");
                } else {
                    this.includeFileExts = new String[]{};
                }
            }
            return this.includeFileExts;
        }

        public String[] getIncludeImgExts() {
            if (this.includeImgExts == null) {
                if (!StringUtils.isEmpty(this.imgType)) {
                    this.includeImgExts = this.imgType.split(",");
                } else {
                    this.includeImgExts = new String[]{};
                }
            }
            return this.includeImgExts;
        }

        public Long getBufferSize() {
            return bufferSize;
        }

        public void setBufferSize(Long bufferSize) {
            this.bufferSize = bufferSize;
        }

        public Long getMaxSize() {
            return maxSize;
        }

        public void setMaxSize(Long maxSize) {
            this.maxSize = maxSize;
        }

        public String getDefaultEncoding() {
            return defaultEncoding;
        }

        public void setDefaultEncoding(String defaultEncoding) {
            this.defaultEncoding = defaultEncoding;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getImgType() {
            return imgType;
        }

        public void setImgType(String imgType) {
            this.imgType = imgType;
        }

        public String getStaticImageServer() {
            return staticImageServer;
        }

        public void setStaticImageServer(String staticImageServer) {
            this.staticImageServer = staticImageServer;
        }

        public String getBucketName() {
            return bucketName;
        }

        public void setBucketName(String bucketName) {
            this.bucketName = bucketName;
        }

        public String getEndpoint() {
            return endpoint;
        }

        public void setEndpoint(String endpoint) {
            this.endpoint = endpoint;
        }

        public Integer getPort() {
            return port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

        public Boolean getHttps() {
            return https;
        }

        public void setHttps(Boolean https) {
            this.https = https;
        }

        public String getAccessKey() {
            return accessKey;
        }

        public void setAccessKey(String accessKey) {
            this.accessKey = accessKey;
        }

        public String getSecretKey() {
            return secretKey;
        }

        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
    }

    public static class Message {
        /**
         * 不允许上传后缀的提示
         **/
        private String notAllowedExt = "文件类型不符合要求";
        private String notAllowedSize = "文件超过指定大小";
        private String emptyFile = "上传文件不能为空";
        private String apiRequestFail = "接口请求异常";

        private String limitedFail = "操作频繁,请稍后试";
        private String illegalWordsFail = "存在敏感词汇,请替换后在试";

        /**
         * 未登录或token失效
         * **/
        private String tokenFail="未登录或token已过期";
        private String tokenExpFail="token已过期";
        private String tokenUnsupportFail="不支持的token";
        private String tokenIllegalFail="非法token";
        /**
         * 授权失败
         * **/
        private String authFail="未授权的访问";

        public String getTokenUnsupportFail() {
            return tokenUnsupportFail;
        }

        public void setTokenUnsupportFail(String tokenUnsupportFail) {
            this.tokenUnsupportFail = tokenUnsupportFail;
        }

        public String getTokenIllegalFail() {
            return tokenIllegalFail;
        }

        public void setTokenIllegalFail(String tokenIllegalFail) {
            this.tokenIllegalFail = tokenIllegalFail;
        }

        public String getTokenExpFail() {
            return tokenExpFail;
        }

        public void setTokenExpFail(String tokenExpFail) {
            this.tokenExpFail = tokenExpFail;
        }

        public String getTokenFail() {
            return tokenFail;
        }

        public void setTokenFail(String tokenFail) {
            this.tokenFail = tokenFail;
        }

        public String getAuthFail() {
            return authFail;
        }

        public void setAuthFail(String authFail) {
            this.authFail = authFail;
        }

        public String getNotAllowedExt() {
            return notAllowedExt;
        }

        public void setNotAllowedExt(String notAllowedExt) {
            this.notAllowedExt = notAllowedExt;
        }

        public String getApiRequestFail() {
            return apiRequestFail;
        }

        public void setApiRequestFail(String apiRequestFail) {
            this.apiRequestFail = apiRequestFail;
        }

        public String getNotAllowedSize() {
            return notAllowedSize;
        }

        public void setNotAllowedSize(String notAllowedSize) {
            this.notAllowedSize = notAllowedSize;
        }

        public String getEmptyFile() {
            return emptyFile;
        }

        public void setEmptyFile(String emptyFile) {
            this.emptyFile = emptyFile;
        }

        public String getLimitedFail() {
            return limitedFail;
        }

        public void setLimitedFail(String limitedFail) {
            this.limitedFail = limitedFail;
        }

        public String getIllegalWordsFail() {
            return illegalWordsFail;
        }

        public void setIllegalWordsFail(String illegalWordsFail) {
            this.illegalWordsFail = illegalWordsFail;
        }

    }
    public Message getMessage() {
        return message;
    }
    public Minio getMinio() {
        return minio;
    }
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getVersion()
    {
        return version;
    }

    public void setVersion(String version)
    {
        this.version = version;
    }

    public String getCopyrightYear()
    {
        return copyrightYear;
    }

    public void setCopyrightYear(String copyrightYear)
    {
        this.copyrightYear = copyrightYear;
    }

    public static String getProfile()
    {
        return profile;
    }

    public void setProfile(String profile)
    {
        RuoYiConfig.profile = profile;
    }

    public static boolean isAddressEnabled()
    {
        return addressEnabled;
    }

    public void setAddressEnabled(boolean addressEnabled)
    {
        RuoYiConfig.addressEnabled = addressEnabled;
    }

    public static String getCaptchaType() {
        return captchaType;
    }

    public void setCaptchaType(String captchaType) {
        RuoYiConfig.captchaType = captchaType;
    }

    /**
     * 获取导入上传路径
     */
    public static String getImportPath()
    {
        return getProfile() + "/import";
    }

    /**
     * 获取头像上传路径
     */
    public static String getAvatarPath()
    {
        return getProfile() + "/avatar";
    }

    /**
     * 获取下载路径
     */
    public static String getDownloadPath()
    {
        return getProfile() + "/download/";
    }

    /**
     * 获取上传路径
     */
    public static String getUploadPath()
    {
        return getProfile() + "/upload";
    }
}
